/**
 * SHT30温湿度传感器驱动头文件
 * 使用I2C接口通信
 */

#ifndef __SHT30_H
#define __SHT30_H

#include "stm32f10x.h"

// SHT30 I2C地址
#define SHT30_I2C_ADDR          0x44  // 7位地址
#define SHT30_I2C_ADDR_WRITE    (SHT30_I2C_ADDR << 1)
#define SHT30_I2C_ADDR_READ     ((SHT30_I2C_ADDR << 1) | 0x01)

// SHT30命令
#define SHT30_CMD_READSTATUS    0xF32D
#define SHT30_CMD_CLEARSTATUS   0x3041
#define SHT30_CMD_SOFTRESET     0x30A2
#define SHT30_CMD_HEATER_ENABLE 0x306D
#define SHT30_CMD_HEATER_DISABLE 0x3066
#define SHT30_CMD_READOUT       0xE000

// 测量命令 (单次测量，时钟拉伸禁用，高精度)
#define SHT30_CMD_MEAS_CLOCKSTR_H  0x2C06
#define SHT30_CMD_MEAS_CLOCKSTR_M  0x2C0D
#define SHT30_CMD_MEAS_CLOCKSTR_L  0x2C10

// 函数声明
void SHT30_Init(void);
uint8_t SHT30_Read(float *temperature, float *humidity);
uint8_t SHT30_SoftReset(void);
uint8_t SHT30_ReadStatus(uint16_t *status);
uint8_t SHT30_CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum);

#endif
